# coding: utf-8
from enum import Enum
from pathlib import Path

from PySide6.QtCore import QFile, QIODeviceBase
from PySide6.QtWidgets import QWidget

from .settings import RESOURCE_DIR


class StyleSheet(Enum):
    """ 样式表基类 """
    PLAYER = 'player'

    def path(self):
        """ 获取样式表的路径 """
        return (RESOURCE_DIR / f'qss/{self.value}.css').as_posix()

    def content(self):
        """ 获取样式表的内容 """
        f = QFile(self.path())
        f.open(QIODeviceBase.OpenModeFlag.ReadOnly)
        qss = str(f.readAll(), encoding='utf-8')
        f.close()
        return qss

    def apply(self, widget: QWidget):
        """ 将样式表应用于小部件 """
        qss = self.content()
        widget.setStyleSheet(qss)
